<!-- 预警模型 -->
<script>
import { highIncidenceFindListByPage } from '@/api/rule'
import QueryTable from '@/mixins/QueryTable'
import indexDialog from './indexDialog'
import { submitApi } from './submit'

export default {
  name: 'indexTable',
  extends: QueryTable,
  components: {
    indexDialog
  },
  data() {
    const areaCode = this.$store.state.user.user.districtNo
    return {
      FormDialogVisible: false,
      inputList: {
        data: [
          {
            type: 'select',
            label: '适用区域',
            prop: 'applicableArea',
            list: []
          },
          {
            type: 'select',
            label: '规则状态',
            prop: 'ruleStatus',
            list: []
          }
        ]
      },
      tableApi: highIncidenceFindListByPage, // 表格数据API
      tableConfig: {
        columns: [
          {
            label: '规则适用区域',
            prop: 'ruleApplicationDistrictName',
            showTooltip: true
          },
          {
            label: '模型状态',
            prop: 'modelStatus',
            showTooltip: true,
            render: () => {
              return {
                default: ({ row }) => {
                  return row.modelStatus == 1 ? '已开启' : '已关闭'
                }
              }
            }
          },
          {
            label: '规则状态',
            prop: 'ruleStatus',
            showTooltip: true,
            render: () => {
              return {
                default: ({ row }) => {
                  return row.ruleStatus == 0 ? '待激活' : '已激活'
                }
              }
            }
          },
          {
            label: '更新时间',
            prop: 'updateTime',
            showTooltip: true
          }
        ],
        btns: [
          {
            text: '规则配置',
            hide: (row) => row.ruleStatus == '0',
            methods: (row) => this.targetStatus(row, '规则配置')
          },
          {
            text: '激活',
            hide: (row) => row.ruleStatus == '1',
            methods: (row) => this.targetStatus(row, '激活')
          }
        ]
      },
      customQueryParam: {
        areaCode
      },
      row: {},
      data: {}
    }
  },
  computed: {},
  created() {
    this.getDict()
  },

  mounted() {},

  methods: {
    getDict() {
      this.inputList.data[0].list = [
        { label: '本区域', value: 1 },
        { label: '下级区域', value: 2 }
      ]
      this.inputList.data[1].list = [
        { label: '全部', value: '' },
        { label: '待激活', value: 1 },
        { label: '已激活', value: 2 }
      ]
    },
    getDefaultModel() {
      return {
        applicableArea: 1,
        ruleStatus: ''
      }
    },
    handleView(row) {
      this.$router.push({
        path: '/type/Publish/PublishDetail',
        query: {
          id: row.id,
          flowStatue: row.flowStatue,
          itemCode: row.itemCode,
          areaCode: row.areaCode
        }
      })
    },
    targetStatus(row, type) {
      this.row = row
      switch (type) {
        case '规则配置':
          this.FormDialogVisible = true
          break
        case '激活':
          this.FormDialogVisible = true
          break
      }
    },
    renderExternal() {
      return (
        <indexDialog
          visible={this.FormDialogVisible}
          data={this.row}
          {...{
            on: {
              submit: (data) => {
                this.data = data
                submitApi.call(this)
              },
              close: () => {
                this.FormDialogVisible = false
                this.row = {}
              }
            }
          }}
        ></indexDialog>
      )
    }
  }
}
</script>
